var order500 = function (orderType,pay,stack) {
    if(orderType === 1 && pay){
        console.log("购买500定金，反100优惠券");
    }else {
        return 'nextSuccessor'
    }
}
var order200 = function (orderType,pay,stack) {
    if(orderType === 2 && pay){
        console.log("购买200定金，反50优惠券");
    }else {
        return 'nextSuccessor'
    }
}
var orderNormal = function (orderType,pay,stack) {
    if(stack > 0) {
        console.log("无优惠购买产品");
    }else {
        console.log("没有库存啦");
    }
}

class Chain {
    constructor(func) {
        this.func = func;
        this.success = null
    }

    addSuccess(fn) {
       return this.success = fn
    }

    passRequest() {
        var result = this.func.apply(this,arguments)
        if(result === 'nextSuccessor'){
            return this.success && this.success.passRequest.apply(this.success,arguments)
        }
        return result
    }
}

var fiveMillon = new Chain(order500)
var twoMillon = new Chain(order200)
var normal = new Chain(orderNormal)
fiveMillon.addSuccess(twoMillon)
twoMillon.addSuccess(normal)

fiveMillon.passRequest(2,false,2)
twoMillon.passRequest(2,false,2)